package cn.stronglink.assetmanage.business.task.model;

import java.util.ArrayList;
import java.util.List;

import cn.stronglink.assetmanage.MyApplication;
import cn.stronglink.assetmanage.dao.CheckDao;
import cn.stronglink.assetmanage.dao.DaoManager;
import cn.stronglink.assetmanage.dao.DaoSession;
import cn.stronglink.assetmanage.dao.InventoryDao;
import cn.stronglink.assetmanage.dao.PatrolDao;
import cn.stronglink.assetmanage.dao.RepairDao;
import cn.stronglink.assetmanage.dao.TaskDao;
import cn.stronglink.assetmanage.entity.Check;
import cn.stronglink.assetmanage.entity.Inventory;
import cn.stronglink.assetmanage.entity.Patrol;
import cn.stronglink.assetmanage.entity.Repair;
import cn.stronglink.assetmanage.entity.Task;
import cn.stronglink.assetmanage.utils.Constants;

/**
 * Created by chencongcong on 2018/6/18.
 */

public class TaskOperateModel {
    public List<Task> getOpreateList(){
        List<Task> taskList = new ArrayList<>();
//        List<Task> checkList =  DaoManager.getInstance(MyApplication.APP_CONTEXT).getDaoSession().getTaskDao().
//                queryBuilder().where(TaskDao.Properties.BusinessType.eq(Constants.STATUS_ONE)).
//                where(TaskDao.Properties.Status.notEq(Constants.STATUS_THREE)).list();
//        List<Task> inventoryTask = DaoManager.getInstance(MyApplication.APP_CONTEXT).getDaoSession().getTaskDao().
//                queryBuilder().where(TaskDao.Properties.BusinessType.eq(Constants.STATUS_TWO)).
//                where(TaskDao.Properties.Status.notEq(Constants.STATUS_ONE)).list();
//        List<Task> patrolTask =  DaoManager.getInstance(MyApplication.APP_CONTEXT).getDaoSession().getTaskDao().
//                queryBuilder().where(TaskDao.Properties.BusinessType.eq(Constants.STATUS_THREE)).
//                where(TaskDao.Properties.Status.notEq(Constants.STATUS_ONE)).list();
//        List<Task> repairTask = DaoManager.getInstance(MyApplication.APP_CONTEXT).getDaoSession().getTaskDao().
//                queryBuilder().where(TaskDao.Properties.BusinessType.eq(Constants.STATUS_FOUR)).
//                where(TaskDao.Properties.Status.notEq(Constants.STATUS_ONE)).list();
//        taskList.addAll(checkList);
//        taskList.addAll(inventoryTask);
//        taskList.addAll(patrolTask);
//        taskList.addAll(repairTask);
//        if(taskList!=null){
//            return taskList;
//        }
        DaoSession session = DaoManager.getDaoSession(MyApplication.APP_CONTEXT);
        List<Check> checkList = session.getCheckDao().queryBuilder().where(CheckDao.Properties.Status.eq(4)).list();
        List<Inventory> inventorieList = session.getInventoryDao().queryBuilder().where(InventoryDao.Properties.Status.eq(3)).list();
        List<Repair> repairList= session.getRepairDao().queryBuilder().where(RepairDao.Properties.Status.eq(3)).list();
        List<Patrol> patrolList =  session.getPatrolDao().queryBuilder().where(PatrolDao.Properties.Status.eq(3)).list();
        if(checkList!=null&&checkList.size()>0){
            for(Check check:checkList){
                Task task = new Task();
                task.setId_(check.getId_());
                task.setStatus(check.getStatus());
                task.setBusinessType(1);
                task.setStatusName("已入库");
                taskList.add(task);
            }
        }

        if(inventorieList!=null&&inventorieList.size()>0){
            for(Inventory inventory:inventorieList){
                Task task = new Task();
                task.setId_(inventory.getId_());
                task.setStatus(inventory.getStatus());
                task.setBusinessType(2);
                task.setStatusName("已盘点");
                taskList.add(task);
            }
        }

        if(repairList!=null&&repairList.size()>0){
            for(Repair repair:repairList){
                Task task = new Task();
                task.setId_(repair.getId_());
                task.setStatus(repair.getStatus());
                task.setBusinessType(3);
                task.setStatusName("已维修");
                taskList.add(task);
            }
        }

        if(patrolList!=null&&patrolList.size()>0){
            for(Patrol patrol:patrolList){
                Task task = new Task();
                task.setId_(patrol.getId_());
                task.setStatus(patrol.getStatus());
                task.setBusinessType(4);
                task.setStatusName("已巡检");
                taskList.add(task);
            }
        }
        return  taskList;
    }
}
